import initialState from "./state";
import { ActionType, Action } from "../types/user";

function userReducer(state = initialState, action: Action) {
  const { type, payload } = action

  if (type === ActionType['AUTH_CODE']) {
    Object.assign({}, state, payload)
    return state
  }

  if (type === ActionType['LOGIN_USER']) {
    Object.assign({}, state, payload)
    return state
  }

  if (type === ActionType['SET_TOKEN']) {
    return {
      ...state,
      token: payload
    }
  }

  return state
}

export default userReducer